<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <%@ include file="top_new.jsp"%> 
</head>
<body>
  <div class="panel admin-panel">
  <div class="padding border-bottom layui-form-item">
    <div class="layui-input-inline">
      <input type="text" name="fvalue" id = "fvalue" placeholder="作者名称" autocomplete="off" class="layui-input">
    </div>
    <button class="layui-btn" id ="query">查询</button>
    <button class="layui-btn" id ="bt_add">添加</button>
  </div>
<table class="layui-table">
  <colgroup>
    <col width="150">
    <col width="300">
    <col width="300">
    <col width="200">
  </colgroup>
  <thead>
    <tr>
      <input type='hidden' name='fstats' id="fstats">
      <th data-fileds ="fid" name ="fid" id="fid">选择</th>
      <th data-fildes ="fname" name ="fname" id="fname">字典名称</th>
      <th data-fildes ="fsortcode" name ="fsortcode" id="fsortcode">分类编码</th>
      <th >操作</th>
    </tr> 
  </thead>
  <tbody id = "t_tbody">
    
      </tbody>
     <tr>
        <td colspan="4"><div id="div_page"></div></td>
     </tr>
</table>  
  </div>
<script type="text/javascript">
window.onload=function() {
	$.post("<%=basePath%>tdic/tdicsort_list",
		    {
				page:1,
				pagesize:10
		    },
		    function(res){
		    	if (res.errorCode == 0) {
		    		var data=res.data;
		    		laypage({
		    		      cont: 'div_page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
		    		      pages: data.totalPage, //通过后台拿到的总页数
		    		      curr: data.pageNumber, //当前页
		    		      jump: function(obj, first){ //触发分页后的回调
		    		    	  
		    		    	  if(!first){
		    		    		  $("#t_tbody").empty();
			    		    	  $.post("<%=basePath%>tdic/tdicsort_list",
			    		    			    {
			    		    					page:obj.curr,
			    		    					pagesize:10,
			    		    					fvalue:$("#fvalue").val()
			    		    			    },
			    		    			    function(res){
			    		    			    	var tbody ="";
		    		    			    		if (res.errorCode == 0) {
			    		    			    		 tbody = pageDataCheck(res.data.list,1);  
		    		    			    		}
		    		    			    		$("#t_tbody").append(tbody);  
			    		    			    });
		    		    	  }else{
		    		    		   var tbody ="";
		    		    		   tbody = pageDataCheck(data.list,1);  
		    			    	   $("#t_tbody").append(tbody);  
		    		    	  }
		    		      }
		    		});
		    	}else{
		    		if (res.errorCode == 2) {
		    			layer.alert(res.message) ;
		    		}else{
		    			layer.msg("参数错误："+res.message, {shift: 6});
		    		}
		    	}
		    }); 
	
};
$("#bt_add").click(function(){
	var diag = new top.Dialog();
    diag.Drag=true;
    diag.Title ="字典信息";
    diag.URL = '<%=basePath%>tdic/tdicsort_edit';
    diag.Width = 400;
    diag.Height = 400;
    diag.CancelEvent = function(){ //关闭事件
    	var isLoad = diag.innerFrame.contentWindow.document.getElementById("isLoad").value;
    	if(isLoad == '1'){
    		queryList();
    	}
        diag.close();
    };
    diag.show();
});
function queryList(){
	 var fvalue = $("#fvalue").val();
	  $("#t_tbody").empty();
	 $.post("<%=basePath%>tdic/tdicsort_list",
			    {
					page:1,
					pagesize:5,
					fvalue:fvalue
			    },
			    function(res){
			    	if (res.errorCode == 0) {
			    		var data=res.data;
			    		laypage({
			    		      cont: 'div_page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
			    		      pages: data.totalPage, //通过后台拿到的总页数
			    		      curr: data.pageNumber, //当前页
			    		      jump: function(obj, first){ //触发分页后的回调
			    		    	  $.post("<%=basePath%>tdic/tdicsort_list",
			    		    			    {
			    		    					page:obj.curr,
			    		    					pagesize:5,
			    		    					fvalue:fvalue
			    		    			    },
			    		    			    function(res){
		    		    			    		if (res.errorCode == 0) {
		    		    			    			var tbody ="";
			    		    			    		if (res.errorCode == 0) {
				    		    			    		 tbody = pageDataCheck(res.data.list,1);  
			    		    			    		}
			    		    			    		$("#t_tbody").append(tbody);    
		    		    			    		}
			    		    			    });
			    		      }
			    		});
			    	}else{
			    		if (res.errorCode == 2) {
			    			layer.alert(res.message) ;
			    		}else{
			    			layer.msg("参数错误："+res.message, {shift: 6});
			    		}
			    	}
			    }); 
}
$("#query").click(function(){ 
	queryList();
})
function del(id){
	if(confirm("您确定要删除吗?")){
		$.post("<%=basePath%>tdic/delTdic",
			    {
					fid:id
			    },
			    function(ret){
			    	if (ret.isOk) {
			    		queryList();
			    	}else{
			    		layer.alert(res.message);
			    	}
			    }); 
	}
}
function eidt(id){
	var diag = new top.Dialog();
    diag.Drag=true;
    diag.Title ="字典信息";
    diag.URL = '<%=basePath%>tdic/tdicsort_edit?fid='+id;
    diag.Width = 400;
    diag.Height = 400;
    diag.CancelEvent = function(){ //关闭事件
    	var isLoad = diag.innerFrame.contentWindow.document.getElementById("isLoad").value;
    	if(isLoad == '1'){
    		queryList();
    	}
        diag.close();
    };
    diag.show();
}
$("#checkall").click(function(){ 
  $("input[name='id']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

function DelSelect(){
	var Checkbox=false;
	 $("input[name='id']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false; 		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

</script>
</body></html>